/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package course.providers.jpa;

import course.entities.UserActivity;
import java.io.Serializable;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author def
 */
@Stateless
public class UserActivityProvider implements Serializable {

    private static final long serialVersionUID = 5734065238354852186L;

    @PersistenceContext(unitName = "webPartPU")
    protected EntityManager em;

    public UserActivityProvider() {
    }

    public UserActivity create() {
        UserActivity entity = new UserActivity();
        em.persist(entity);
        return entity;
    }

    public void update(UserActivity entity) {
        em.merge(entity);
    }

    public void delete(UserActivity entity) {
        em.remove(em.merge(entity));
    }
    
    public UserActivity findById(long id) {
        return (UserActivity) em.find(UserActivity.class, id);
    }

    public List<UserActivity> findAll() {
        Query q = em.createNamedQuery("UserActivity.findAll");
        return (List<UserActivity>) q.getResultList();
    }

}
